package org.ipb.controller.modul.gelarpendidikan;

import org.ipb.model.GelarPendidikan;

import util.hibernate.DAO;

import com.opensymphony.xwork2.ActionSupport;

public class ActionJQGridCrud extends ActionSupport {
	private static final long serialVersionUID = -5933849517817526086L;

	private String id;
	private String gelar;
	private String nama;
	private String posisi;

	public String getPosisi() {
		return posisi;
	}

	public void setPosisi(String posisi) {
		this.posisi = posisi;
	}

	private String oper;

	public String getOper() {
		return oper;
	}

	public String getGelar() {
		return gelar;
	}

	public void setGelar(String gelar) {
		this.gelar = gelar;
	}

	public void setOper(String oper) {
		this.oper = oper;
	}

	public String execute() {
		if (getOper().equals("edit")) {
			return update();
		} else if (getOper().equals("add")) {
			return insert();
		} else {
			return delete();
		}
	}

	public String insert() {
		DAO<Integer> dao = new DAO<Integer>();
		GelarPendidikan object = new GelarPendidikan();
		object.setNama(getNama());
		object.setGelar(getGelar());
		object.setPosisi(getPosisi());
		dao.insert(object);
		dao.close();
		return SUCCESS;
	}

	public String update() {
		DAO<Integer> dao = new DAO<Integer>();
		GelarPendidikan object = (GelarPendidikan) dao.find(
				GelarPendidikan.class, Integer.valueOf(getId()));
		object.setNama(nama);
		object.setGelar(getGelar());
		object.setPosisi(getPosisi());
		dao.update(object);
		dao.close();
		return SUCCESS;
	}

	public String delete() {
		DAO<Integer> dao = new DAO<Integer>();
		GelarPendidikan delete = (GelarPendidikan) dao.find(
				GelarPendidikan.class, Integer.valueOf(getId()));
		dao.delete(delete);
		dao.close();
		return SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getNama() {
		return nama;
	}

	public void setNama(String nama) {
		this.nama = nama;
	}

}
